import { DataTypes, Model } from "sequelize";
import sequelize from "@db/sequelize";
import { Organization } from "./Organization";

export class Event extends Model {
    declare id: number;
    declare title: string;
    declare organizationId?: number;
    declare skills: string[];
    declare date: string;
    declare members: number[];
}

Event.init(
    {
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
            unique: true,
        },
        title: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        skills: {
            type: DataTypes.JSONB,
            defaultValue: [],
        },
        date: {
            type: DataTypes.DATE,
        },
        members: {
            type: DataTypes.JSONB,
            defaultValue: [],
        },
    },
    {
        tableName: "events",
        sequelize,
    }
);

Organization.hasMany(Event, {
    foreignKey: "organizationId",
});
